package cn.livingCloud.controller.content.validator;

import cn.livingCloud.dto.ReplyRuleFormDto;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 * Created by dingjie on 2015/12/3.
 */
@Component
public class ReplyRuleFormDtoValidator implements Validator {

    public boolean supports(Class<?> aClass) {
        return ReplyRuleFormDto.class.equals(aClass);
    }

    public void validate(Object target, Errors errors) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "keyWord", null, "关键字不能为空");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "content.content", null, "回复内容不能为空");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "msgType", null, "消息类型不能为空");
    }
}
